package input;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import model.Settings;

/**
 * Class that handles all KeyBoard input (as the name implies)
 * @author Tim Cocu
 */
public class KeyBoard implements KeyListener
{
	private boolean[] allKeys = new boolean[65536];
	public boolean moveUp, moveDown, moveRight, moveLeft;
	
	/**
	 * Method that handles all the updates from the keyboard
	 */
	public void updateKeys()
	{
		moveUp = allKeys[KeyEvent.VK_UP] || allKeys[KeyEvent.VK_W];
		moveDown = allKeys[KeyEvent.VK_DOWN] || allKeys[KeyEvent.VK_S];
		moveRight = allKeys[KeyEvent.VK_RIGHT] || allKeys[KeyEvent.VK_D];
		moveLeft = allKeys[KeyEvent.VK_LEFT] || allKeys[KeyEvent.VK_A];
	}
	
	public void keyPressed(KeyEvent keyEvent) 
	{
		checkSettingsKeys(keyEvent);
	
		allKeys[keyEvent.getKeyCode()] = true;
	}
	
	/**
	 * Method for handling settings keys.
	 * @param keyEvent 
	 */
	private void checkSettingsKeys(KeyEvent keyEvent)
	{
		switch(keyEvent.getKeyCode())
		{
			case KeyEvent.VK_F1: Settings.DebugMode = !Settings.DebugMode; break;
			case KeyEvent.VK_F2: Settings.DrawHitboxes = !Settings.DrawHitboxes; break;
			case KeyEvent.VK_F3: Settings.AntiAliasing = !Settings.AntiAliasing; break;
			case KeyEvent.VK_F4: Settings.HighQuality = !Settings.HighQuality; break;
			case KeyEvent.VK_F5: Settings.IsTyping = !Settings.IsTyping; break;
		}
	}

	public void keyReleased(KeyEvent keyEvent) 
	{
		allKeys[keyEvent.getKeyCode()] = false;
	}

	//TODO KEYTYPED NOT IMPLEMENTED
	public void keyTyped(KeyEvent keyEvent) 
	{

	}
	
}
